	/* @(#)DecKanGlResourceBundle.java
	** Copyright (C) 2001-2011 by Steven D. Stamps
	**
	**             Trademarks & Copyrights
	** Flywheel Management Science(TM) and FlywheelMS(TM) are exclusive
	** trademarks of Steven D. Stamps and may only be used freely for
	** the purpose of identifying the unforked version of this software.
	** Subsequent forks (if any) may not use these trademarks.  All other
	** rights are reserved.
	**
	** DecKanGL (Decorated Kanban Glyph Language) and TribKn (Tribal Knowledge)
	** are also exclusive trademarks of Steven D. Stamps.  These may be used
	** freely within the unforked FlywheelMS application and documentation.
	** All other rights are reserved.
	**
	** Trademark information is available at
	** <http://www.flywheelms.org/trademarks>
	**
	** Flywheel Management Science(TM) is a copyrighted body of management
	** metaphors, governance processes, and leadership techniques that is
	** owned by Steven D. Stamps.  These copyrighted materials may be freely
	** used, without alteration, by the community (users and developers)
	** surrounding this GPL3-licensed software.  Additional copyright
	** information is available at <http://www.flywheelms.org/copyrights>
	**
	**              GPL3 Software License
	** This program is free software: you can use it, redistribute it and/or
	** modify it under the terms of the GNU General Public License, version 3,
	** as published by the Free Software Foundation. This program is distributed
	** in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
	** even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
	** PURPOSE.  See the GNU General Public License for more details. You should
	** have received a copy of the GNU General Public License, in a file named
	** COPYING, along with this program.  If you cannot find your copy, see
	** <http://www.gnu.org/licenses/gpl-3.0.html>.
	*/
	package com.fmscorp.deckangl.core;

	import java.awt.Color;
	import java.util.Enumeration;
	import java.util.Iterator;
	import java.util.List;
	import java.util.Map;
	import java.util.ResourceBundle;
	import java.util.logging.Level;
	import java.util.logging.Logger;

	import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;

	public class DecKanGlResourceBundle implements DecKanGlResourceBundleKeys {
	    private static final Logger logger = Logger.getLogger(DecKanGlResourceBundle.class.getName());
	    
	    private static final String BUNDLE_NAME = "com.fmscorp.deckangl.DecKanGL";

	    private static ResourceBundle resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME);
	    private static Configuration config = new BaseConfiguration();

	    static {
	        loadConfiguration();
	    }

	    private static void loadConfiguration() {
	        Enumeration e = resourceBundle.getKeys();
	        while (e.hasMoreElements()) {
	            String key = e.nextElement().toString();
	            if (config.containsKey(key)) {
	                if (logger.isLoggable(Level.WARNING)) {
	                    logger.warning("Duplicate key: " + key + 
	                            " [new=" + resourceBundle.getString(key) + ",old=" +
	                            config.getString(key) + "]");
	                }
	            }
	            config.setProperty(key, resourceBundle.getString(key));
	        }
	    }
	    
	    static String getString(Configuration originalConfig, String key, Map parameters) {
	        Configuration lConfig = new BaseConfiguration();
	        lConfig.addProperty(key, originalConfig.getString(key));
	        for (Iterator i = parameters.keySet().iterator(); i.hasNext();) {
	            String paramKey = i.next().toString();
	            lConfig.addProperty(paramKey, parameters.get(paramKey));
	        }
	        return lConfig.getString(key);
	    }
	    
	    public static String getString(String key, Map parameters) {
	        return getString(config, key, parameters);
	    }

	    public static String getString(String key) {
	        return config.getString(key);
	    }
	    
	    public static String buildString(String... keys) {
	    	StringBuilder buffer = new StringBuilder();
	    	for(String key: keys) {
	    		buffer.append(config.getString(key));
	    	}
	    	return buffer.toString();
	    }
	    
	    public static int getInt(String key) {
	        return config.getInt(key);
	    }
	    
	    public static String[] getStringArray(String key) {
	        return config.getStringArray(key);
	    }

	    public static String getString(List keys) {
	        StringBuffer lBuffer = new StringBuffer();
	        Iterator lIterator = keys.iterator();
	        while (lIterator.hasNext()) {
	            lBuffer.append(config.getString((String) lIterator.next()));
	        }

	        return lBuffer.toString();
	    }

	    public static String getString(String[] keys) {
	        StringBuffer lBuffer = new StringBuffer();
	        for (int i = 0; i < keys.length; i++) {
	            lBuffer.append(config.getString(keys[i]));
	        }

	        return lBuffer.toString();
	    }

	    public static String getLabel(String key) {
	        return getString(key) + getString(separator_COLON);
	    }

	    public static Color getColor(String aResourceKey) {
	        String theColorString = "0x" + getString(aResourceKey);
	        return new Color(Integer.decode(theColorString).intValue());
	    }

	    public static String getColorHexValueString(String p_aKey) {
	        return "#" + getString(p_aKey);
	    }
	}
